package com.igoal.dto;

import java.util.Calendar;
import java.util.Date;

import org.apache.commons.lang.StringUtils;

import com.igoal.entity.City;
import com.igoal.entity.User;
import com.igoal.entity.UserInfo;
import com.igoal.utils.SynchronizeAttributeWithOther;
import com.igoal.utils.SynchronizeDirection;

public class UserInfoDTO extends BaseDTO<UserInfo> {

	private String userName;
	private String email;
	private String firstName;
	private String middleName;
	private String lastName;	
	private String mobile;
	private String phone;
	private String address;
	private String district;
	private String cityName;
	private Long cityId;
	private String yahoo;
	private String google;
	private String skype;
	private String aboutMe;
	private String facebook;
	private String website;
	private boolean male;
	private Integer birthdayDate;
	private Integer birthdayMonth;
	private Integer birthdayYear;

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getDistrict() {
		return district;
	}

	public void setDistrict(String district) {
		this.district = district;
	}

	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	public Long getCityId() {
		return cityId;
	}

	public void setCityId(Long cityId) {
		this.cityId = cityId;
	}

	public String getYahoo() {
		return yahoo;
	}

	public void setYahoo(String yahoo) {
		this.yahoo = yahoo;
	}

	public String getGoogle() {
		return google;
	}

	public void setGoogle(String google) {
		this.google = google;
	}

	public String getSkype() {
		return skype;
	}

	public void setSkype(String skype) {
		this.skype = skype;
	}

	public String getAboutMe() {
		return aboutMe;
	}

	public void setAboutMe(String aboutMe) {
		this.aboutMe = aboutMe;
	}

	public String getFacebook() {
		return facebook;
	}

	public void setFacebook(String facebook) {
		this.facebook = facebook;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
	}

	public boolean isMale() {
		return male;
	}
	
	public boolean getMale(){
		return male;
	}

	public void setMale(boolean male) {
		this.male = male;
	}
	
	public String getFullName() {
		StringBuffer fullName = new StringBuffer();
		if(!StringUtils.isBlank(lastName)){
			fullName.append(lastName).append(" ");
		}
		if(!StringUtils.isBlank(middleName)){
			fullName.append(middleName).append(" ");
		}
		if(!StringUtils.isBlank(firstName)){
			fullName.append(firstName);
		}
		if(StringUtils.isBlank(fullName.toString())){
			fullName.append(userName);
		}
		
		return fullName.toString();
	}

	public Integer getBirthdayDate() {
		return birthdayDate;
	}

	public void setBirthdayDate(Integer birthdayDate) {
		this.birthdayDate = birthdayDate;
	}

	public Integer getBirthdayMonth() {
		return birthdayMonth;
	}

	public void setBirthdayMonth(Integer birthdayMonth) {
		this.birthdayMonth = birthdayMonth;
	}

	public Integer getBirthdayYear() {
		return birthdayYear;
	}

	public void setBirthdayYear(Integer birthdayYear) {
		this.birthdayYear = birthdayYear;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.FROM, value="city")
	public void initCity(Object entity){
		if(entity != null){
			City city = (City) entity;
			cityName = city.getCityName();
			cityId = city.getId();
		}
	}
	
	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.FROM, value="birthday")
	public void initBirthday(Object entity){
		if(entity != null){
			Date date = (Date) entity;
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(date);
			birthdayDate = calendar.get(Calendar.DATE);
			birthdayMonth = calendar.get(Calendar.MONTH) + 1;
			birthdayYear = calendar.get(Calendar.YEAR);
		}
	}
	
	@SynchronizeAttributeWithOther(direction=SynchronizeDirection.FROM, value="user")
	public void initUser(Object entity){
		if(entity != null){
			User user = (User) entity;
			this.userName = user.getUsername();
			this.email = user.getEmail();
		}
	}
}
